package com.ihr360.commons.vo;

/**
 * @author tom
 * @date 17-12-20
 */
public class ResultInfo<T> {


    public static final Integer OK = 0;

    public static final Integer INFO = -1;

    public static final Integer ERROR = -2;

    private Integer code;

    private String message;

    private String url;

    private T data;

    public ResultInfo() {

    }

    public ResultInfo(Integer code, String message, String url, T data) {
        this.code = code;
        this.message = message;
        this.url = url;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static class Builder<T> {
        private Integer code;
        private String message;
        private String url;
        private T data;

        public Builder code(Integer code) {
            this.code = code;
            return this;
        }

        public Builder message(String message) {
            this.message = message;
            return this;
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder data(T data) {
            this.data = data;
            return this;
        }

        public ResultInfo<T> build() {
            return new ResultInfo<>(code, message, url, data);
        }

        public ResultInfo<T> success(T data) {
            return new ResultInfo<>(OK, null, null, data);
        }

        public ResultInfo<T> success() {
            return new ResultInfo<>(OK, null, null, null);
        }

        public ResultInfo<T> error(String msg) {
            return new ResultInfo<>(ERROR, msg, null, null);
        }

    }

    public boolean isErrorResult() {
        return ERROR.equals(this.code);
    }


}
